package com.gopay.common.cps.manager.order.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;





import com.gopay.common.cps.dao.order.CpsGenManageOrderQueryDAO;
import com.gopay.common.cps.dao.order.CpsGeneralMainOrderQueryDAO;
import com.gopay.common.cps.manager.order.FullCpsGenManageOrderQueryManager;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import com.gopay.common.domain.cps.CpsGenManageOrder;
import com.gopay.common.domain.cps.vo.FullCpsGenManageOrder;

@Service(value = "fullCpsGenManageOrderQueryManager")
public class FullCpsGenManageOrderQueryManagerImpl implements FullCpsGenManageOrderQueryManager {

    @Resource(name = "cpsGeneralMainOrderQueryDAO")
    private CpsGeneralMainOrderQueryDAO cpsGeneralMainOrderQueryDAO;

    @Resource(name = "cpsGenManageOrderQueryDAO")
    private CpsGenManageOrderQueryDAO cpsGenManageOrderQueryDAO;

    @Override
    public FullCpsGenManageOrder get(Serializable id) {
        CpsGenMainOrder main = cpsGeneralMainOrderQueryDAO.find(CpsGenMainOrder.class, id);
        if (main != null) {
            CpsGenManageOrder mng = cpsGenManageOrderQueryDAO.find(CpsGenManageOrder.class, id);

            if (mng != null) {
                return new FullCpsGenManageOrder(main, mng);
            }
        }
        return null;
    }

    @Override
    public List<FullCpsGenManageOrder> get(Map<Object, Object> paraMap) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<FullCpsGenManageOrder> getAll() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public FullCpsGenManageOrder findByRelevanceGopayOrderId(String relevanceGopayOrderId) {
        CpsGenMainOrder main = cpsGeneralMainOrderQueryDAO.findByRelevanceGopayOrderId(relevanceGopayOrderId);
        if (main != null) {
            CpsGenManageOrder mng = cpsGenManageOrderQueryDAO.find(CpsGenManageOrder.class, main.getGopayOrderId());

            if (mng != null) {
                return new FullCpsGenManageOrder(main, mng);
            }
        }
        return null;
    }
    @Override
    public List<FullCpsGenManageOrder> findByRelevanceGopayOrderIds(String relevanceGopayOrderId) {
    	List<CpsGenMainOrder>list = cpsGeneralMainOrderQueryDAO.findByRelevanceGopayOrderIds(relevanceGopayOrderId);
    	if(list!=null&&list.size()>0){
    		List<FullCpsGenManageOrder> ret=new ArrayList<FullCpsGenManageOrder>();
        	for(CpsGenMainOrder main:list){
        		 if (main != null) {
        	            CpsGenManageOrder mng = cpsGenManageOrderQueryDAO.find(CpsGenManageOrder.class, main.getGopayOrderId());

        	            if (mng != null) {
        	                 ret.add(new FullCpsGenManageOrder(main, mng));
        	            }
        	        }
        	}
        	return ret;
    	}
        return null;
    }

}
